package com.pennywise.service;

import com.pennywise.mapper.UserProfileMapper;
import com.pennywise.model.UserProfile;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class UserProfileService {
    
    private final UserProfileMapper userProfileMapper;
    
    public UserProfile getCurrentProfile() {
        return userProfileMapper.getCurrentProfile();
    }
    
    public void saveProfile(UserProfile profile) {
        LocalDateTime now = LocalDateTime.now();
        profile.setCreateTime(now);
        profile.setUpdateTime(now);
        
        UserProfile existingProfile = getCurrentProfile();
        if (existingProfile == null) {
            userProfileMapper.insert(profile);
        } else {
            profile.setId(existingProfile.getId());
            userProfileMapper.update(profile);
        }
    }
} 